package com.dao;

import org.hibernate.Session;

import entities.Users;
import com.util.*;

public class SaveUsers {
	public void saveUser(Users u){
		Session session=null;
		try{
			session=HbnUtil.getSession();
			session.beginTransaction();
			session.save(u);
			session.beginTransaction().commit();
		}catch(Exception e){
			e.printStackTrace();
			session.beginTransaction().rollback();
		}finally{
			HbnUtil.releaseSession(session);
		}
		System.out.println("Save Users success!!!!!");
	}
	public void saveUserByUser(Users u){
		Session session=null;
		try{
			session=HbnUtil.getSession();
			session.beginTransaction();
			Users user=(Users)session.createQuery("from Users as u where u.email='"
												+u.getEmail()+"'").uniqueResult();
			//user.setMoney(u.getMoney());
			session.update(user);
			session.beginTransaction().commit();
		}catch(Exception e){
			e.printStackTrace();
			session.beginTransaction().rollback();
		}finally{
			HbnUtil.releaseSession(session);
		}
	}
}
